package com.ctosb.classviewer.clazz.cp;

import com.ctosb.classviewer.ClassReader;
import com.ctosb.classviewer.clazz.ClassFile;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class CONSTANT_String_info extends Cp_info {

    private short string_index;

    @Override
    protected void doParse(ClassReader classReader) {
        string_index = classReader.readShort();
    }

    /**
     * 获取string值
     * @Author alan
     * @Date 2020/12/13 10:10 下午
     * @param classFile
     * @return
     */
    public String getValue(ClassFile classFile) {
        CONSTANT_Utf8_info cp_info = (CONSTANT_Utf8_info)classFile.getConstant_pool()[string_index];
        return cp_info.getValue();
    }
}
